<template>
	<view class="p20 ">
		<view class="bg-zs radius20 pr">
			<image src="/static/img/order/title_bg.png" class="pa top0 left0 wh-max" mode=""></image>
			<view class="pr p30 flex" style="min-height: 132rpx;height: fit-content;">
				<image src="/static/img/order/daifuwu.png" class="w60 h60 mr14" mode=""></image>
				<view class="color-fff flex1">
					<view class="">{{data.status_text||data.status}}</view>
					<view class="fs26 mt10">{{data.status_text2||'您的订单'+(data.status_text||'')}}</view>
				</view>
			</view>
		</view>
		<block v-if="data.service_type==2">
			<view class="h20"></view>
			<itemInfo :data="data.service" />
		</block>
		<view class="radius20 p24 bg-fff mt20" v-if="!item9.hide" v-for="(item9,index9) in infoList" :key="index9">
			<view class="fs30 mb12 tit-ac">
				<text>{{item9.title}}</text>
			</view>
			<block v-if="item.value" v-for="(item,index) in item9.list" :key="index">
				<view class="" v-if="item.type=='arr'">
					<block v-for="(item2,index2) in item.value" :key="index2">
						<view class="color-666 pt12">{{item.name+''+(index2+1)}}</view>
						<view v-if="item2[item3.fidle]" class="flex row-between flex-wrap pt12 pb12 ml10"
							v-for="(item3,index3) in item.list" :key="index3">
							<view class="color-666" v-if="item3.name">{{item3.name}}</view>
							<view class="" :class="item3.class">{{item2[item3.fidle]}}</view>
						</view>
					</block>
				</view>
				<view v-else class="flex row-between flex-wrap pt12 pb12">
					<view class="color-666" :class="item.nameClass" v-if="item.name">{{item.name}}</view>
					<block v-if="item.type=='img'">
						<view class="ml10" v-for="(item2,index2) in $paths(item.value)" :key="index2"
							@click="lookImg(item.value,index2)">
							<image :src="item2" class="w200 h200" mode="aspectFit"></image>
						</view>
					</block>
					<view :class="item.class" v-else>{{item.value}}</view>
				</view>
			</block>
		</view>
		<block v-if="data.type==0&&data.service_type==0">
			<view class="text-center mt40">
				<text>客户期望报价：</text>
				<text class="color-red fs30">{{data.expect_price}}</text>
				<text class="color-red">元</text>
			</view>
			<view class="color-999 fs26 mt30">
				<text class="color-red">*</text>
				<text>参考客户期望报价进行报价，更容易被雇佣，请合理提交报价</text>
			</view>
		</block>



		<view class="h120"></view>
		<view class="fixed bottom0 left0 w-max bg-fff flex ">

			<block v-if="data.receive_id">
				<view class="flex1 p20" v-if="data.status==2">
					<u-button type="warning" ripple @click="signinShow=true">立即签到</u-button>
				</view>
				<view class="flex1 p20" v-if="data.status==4">
					<u-button type="warning" ripple @click="verifyShow=!verifyShow">提交核销</u-button>
				</view>
				<view class="flex1 p20" v-if="data.status==7">
					<u-button type="warning" ripple @click="$u.route('/pages/order/evaluate',$params)">查看评价</u-button>
				</view>
				<view class="flex1 p20" v-if="data.status==8">
					<u-button type="warning" plain ripple @click="cancel(2)">拒绝取消</u-button>
				</view>
				<view class="flex1 p20" v-if="data.status==8">
					<u-button type="warning" @click="cancel(1)">同意取消</u-button>
				</view>
			</block>

			<block v-else-if="data.service_type==0">
				<block v-if="data.type==0">
					<view class="flex1 p20" v-if="data.offer_price*1>0">
						<u-button type="warning" plain ripple @click="cancelOffer">取消报价</u-button>
					</view>
					<view class="flex1 p20" v-if="data.offer_price*1>0">
						<u-button type="warning" ripple @click="baojiaShow=true">{{'我已出价'+data.offer_price}}</u-button>
					</view>
					<view class="flex1 p20" v-else-if="data.offer_surplus*1>0">
						<u-button type="warning" ripple @click="baojiaShow=true">出价接单</u-button>
					</view>
				</block>
			</block>
			<block v-else-if="data.service_type==1||data.service_type==2">
				<view class="flex1 p20" v-if="data.type==1">
					<u-button type="warning" ripple @click="receive">抢单</u-button>
				</view>
				<view class="flex1 p20" v-if="data.type==2">
					<u-button type="warning" ripple @click="receive">接单</u-button>
				</view>
				<view class="flex1 p20" v-if="data.type==3">
					<u-button type="warning" disabled ripple >已被抢走</u-button>
				</view>
				<!-- <view class="flex1 p20" v-if="data.type==4">
					<u-button type="warning" ripple @click="">已接单</u-button>
				</view> -->
			</block>
		</view>
		<u-popup mode="bottom" v-model="verifyShow" borderRadius="32" zIndex="999" height="1000">
			<view class="p20 bg-f8f h-max">
				<view class="radius20 p24 bg-fff mt20" v-if="data.service&&data.service.is_verify">
					<view class="fs30 pb12 pr">
						<text>确认码在下单用户的页面详情中</text>
					</view>
					<view class="color-zs">填写确认码：</view>
					<view class="flex">
						<u-message-input @change="e=>formV.verify_code=e" :maxlength="8" breathe font-size="40"
							width="62">
						</u-message-input>
					</view>
				</view>

				<view class="radius20 p24 bg-fff mt20">
					<view class="fs30 pb12 pr">
						<text>请填写服务内容(非必填)</text>
					</view>
					<view class="w-max p20 bg-f5f radius20">
						<u-input type="textarea" v-model="formV.service_content" placeholder="请填写服务信息"
							:clearable="false"></u-input>
					</view>
				</view>
				<block v-if="data.service&&data.service.items">
					<block v-for="(value,key) in data.service.items" :key="key">
						<view class="radius20 p24 bg-fff mt20">
							<view class="fs30 pb12 pr">
								<text class="color-red">*</text>
								<text>{{value}}</text>
							</view>
							<view class="">
								<imgList @success="ids=>formV[key]=ids" max="9"></imgList>
							</view>
						</view>
					</block>
				</block>
				<view class="h20"></view>
				<u-button type="warning" ripple @click="verify">确认</u-button>
			</view>
		</u-popup>
		<u-popup mode="center" v-model="baojiaShow" width="650" borderRadius="32" closeable>
			<view class="p34">
				<view class="fs32 fw-w tc pb20">{{data.offer_price*1?'修改报价':'立即报价'}}</view>
				<u-form-item label="金额" :borderBottom="false">
					<u-input inputAlign="right" v-model="offerForm.offer_price" placeholder="请输入报价金额" />
				</u-form-item>
				<view class="color-999 fs26 ">
					<text class="color-red">*</text><text>客户期望报价：</text>
					<text class="color-red fs30">{{data.expect_price}}</text>
					<text class="color-red">元</text>
				</view>
				<view class="mt20 p20 bg-f8f radius16" style="border: dashed 2rpx #cfcfcf;">
					<u-input type="textarea" v-model="offerForm.remarks" placeholder="如有特殊要求您可以留言给客户进行说明" />
				</view>
				<view class="h20"></view>
				<u-button type="warning" ripple @click="offer">提交</u-button>
			</view>
		</u-popup>

		<u-popup mode="center" v-model="qiangShow" width="650" borderRadius="20" closeable>
			<view class="p34 flex-col col-center">
				<view class="fs32 fw-w pb40">抢单成功</view>
				<view class="fs30">您可以在订单-待服务中查看</view>
				<view class="h80"></view>
				<view class="w400">
					<u-button type="warning" ripple @click="qiangShow=!qiangShow">知道了</u-button>
				</view>
			</view>
		</u-popup>

		<u-popup mode="center" v-model="signinShow" width="550" borderRadius="20" closeable>
			<view class="p60 flex-col col-center">
				<view class="fs32 fw-w pt20">请确认是否已到达目标地点？</view>
				<view class="h60"></view>
				<view class="w-max flex row-between">
					<view class="w200">
						<u-button type="warning" ripple @click="signin">立即签到</u-button>
					</view>
					<view class="w200">
						<u-button type="warning" plain ripple @click="signinShow=false">取消</u-button>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				signinShow: false,
				baojiaShow: false,
				qiangShow: false,
				data: '',
				verifyShow: false,
				formV: {
					verify_code: '', //确认码
					service_content: '',
					pics: '',
					drugs_pic: '',
					bill_pic: '',
					express_pic: '',
				},
				offerForm: { //报价
					offer_price: '',
					remarks: '',
				},

			};
		},
		onShow() {
			this.getData()
		},
		methods: {
			lookImg(value,index){
				this.$tool.lookImg(this.$paths(value),index)
			},
			signin() { //签到
				this.signinShow = false
				let obj = {
					type: 'gcj02',
					success: (res2) => {
						this.$setCache('location', res2)
						let params = {
							...this.$params,
							...res2
						}
						this.$request('/master/task/signin', params).then(res => {
							this.$msg(res.msg)
							this.getData()
						})
					},
					fail(err) {
						console.log('err', err);
					},
				}
				uni.getLocation(obj);
			},
			cancel(status) {
				this.$showModal((status == 1 ? '同意' : '拒绝') + "取消").then(res => {
					this.$request('/master/order/check', {
						...this.$params,
						status,
					}).then(res => {
						this.$msg(res.msg)
						this.getData()
					})
				})
			},
			getData() {
				this.$request('/master/index/details', this.$params).then(res => {
					this.data = res.data
				})
			},
			offer() { //立即报价
				this.offerForm.order_id = this.$params.order_id
				if (!this.offerForm.offer_price) return this.$msg('请正确填写价格')
				this.$request('/master/index/offer', this.offerForm).then(res => {
					this.$msg(res.msg)
					this.baojiaShow = false
					this.getData()
				})
			},
			cancelOffer() { //接单/抢单
				this.$showModal("取消报价").then(res => {
					this.$request('/master/index/cancelOffer', this.$params).then(res => {
						this.$msg(res.msg)
						this.getData()
					})
				})
			},
			receive() { //接单/抢单
				this.$showModal(this.data.type == 1 ? '抢单' : "接单").then(res => {
					this.$request('/master/index/receive', this.$params).then(res => {
						this.$msg(res.msg)
						this.baojiaShow = false
						this.getData()
					})
				})
			},

			del() { //删除订单
				this.$showModal("删除订单").then(res => {
					this.$request('/master/order/delete', this.$params).then(res => {
						this.$msg(res.msg)
						this.getData()
					})
				})
			},
			verify() { //提交核销
				let params = {
					...this.$params,
					...this.formV
				}
				// if (!params.verify_code) return this.$msg('请填写确认码')
				this.$request('/master/order/verify', params).then(res => {
					this.$msg(res.msg)
					this.getData()
					this.verifyShow = !this.verifyShow
				})
			},
		},
		computed: {
			infoList() {
				let data = this.data || ''
				let arr = [{
						title: '基本信息',
						list: [{
								name: '服务类型',
								value: data.service_name,
								class: 'color-zs'
							},
							{
								name: '期望就诊时间',
								value: data.expect_time
							},
							{
								name: '医院',
								value: data.hospital,
							},
							{
								name: '科室',
								value: data.department,
								class: 'color-zs'
							},
							{
								name: '预约人电话',
								value: data.mobile,
							},
							{
								name: '药品',
								value: data.drugs, //
								type: 'arr',
								list: [{
										name: '企业',
										fidle: 'drugs_factory'
									},
									{
										name: '药品名称',
										fidle: 'drugs_name'
									}, {
										name: '数量',
										fidle: 'drugs_num'
									}, {
										name: '规格',
										fidle: 'drugs_specs'
									}
								]
							},
							{
								name: '0普通号 1专家号',
								value: data.register_type,
							},
							{
								name: '医生',
								value: data.doctor,
							},
							{
								name: '陪诊师性别',
								value: this.$list('sex')[data.master_sex],
							},
							{
								name: '报告类型',
								value: data.report_type,
							},
							{
								name: '是否保价',
								value: data.is_insured === 1 ? '是' : data.is_insured == 0 ? '否' : '',
							},
							{
								name: '是否需要发票',
								value: data.is_invoice === 1 ? '是' : data.is_invoice == 0 ? '否' : '',
							},
							{
								name: '登记号',
								value: data.register_no,
							},
							{
								name: '就诊二维码',
								value: data.qr_code,
								type: 'img'
							},
							{
								name: '报告单条形码',
								value: data.bar_code,
								type: 'img'
							},
							{
								name: '药品名称',
								value: data.drugs_name,
							},
							{
								name: '0非处方药,1处方药',
								value: data.drugs_type,
							},
							{
								name: '处方照片',
								value: data.prescription,
								type: 'img'
							},
							{
								name: '床号',
								value: data.bed_num,
							},
							{
								name: '自理能力',
								value: data.ability,
							},
							{
								name: '服务天数',
								value: data.days,
							},
							{
								name: '诊断结果',
								value: data.results,
							},
							{
								name: '服务需求',
								value: data.remarks,
							},
							{
								name: '',
								value: data.images,
								type: 'img',
								nameClass: 'w-max pb20'
							},
						]
					},
					{
						title: '就诊人信息',
						list: [{
								name: '与就诊人关系',
								value: data.patient?.relation
							},
							{
								name: '就诊人',
								value: data.patient?.name
							},
							{
								name: '就诊人身份证号',
								value: data.patient?.card_no
							},
							{
								name: '就诊人电话',
								value: data.patient?.phone
							},
							{
								name: '就诊人性别',
								value: this.$list('sex')[data.patient?.sex]
							},
							{
								name: '就诊人年龄',
								value: data.patient?.age
							},
						]
					},
					{
						hide:!data.address,
						title: '地址信息',
						list: [{
								name: '姓名',
								value: data.address?.name
							},
							{
								name: '手机号',
								value: data.address?.mobile
							},
							{
								name: '详细地址',
								value: data.address?.address
							}
						]

					},
					{
						title: '订单信息',
						list: [{
								name: '订单编号',
								value: data.order_sn,
							},
							{
								name: '订单金额',
								value: data.actual_price,
							},
							{
								name: '优惠金额',
								value: data.coupon_price * 1 && data.coupon_price,
								class: "color-fs"
							},
							{
								name: '保价服务费',
								value: data.insured_price * 1 && data.insured_price,
							},
							{
								name: '实付金额',
								value: data.pay_price,
								class: "color-fs"
							},
							{
								name: '下单用户',
								value: data.m_name,
							},
							{
								name: '下单用户手机号',
								value: data.m_mobile,
							},
							{
								name: '下单时间',
								value: data.add_time,
							},
							{
								name: '雇佣时间',
								value: data.hire_time,
							},
							{
								name: '签到时间',
								value: data.signin_time,
							},
							{
								name: '服务开始时间',
								value: data.expect_time,
							},
							{
								name: '核销时间',
								value: data.verify_time,
							},
							{
								name: '验收时间',
								value: data.check_time,
							},
							{
								name: '服务内容',
								value: data.receive?.service_content || '',
							},
							{
								name: '服务照片',
								value: data.receive?.pics || '',
								type: 'img',
								nameClass: 'w-max pb20'
							},
							{
								name: '药品照片',
								value: data.receive?.drugs_pic || '',
								type: 'img',
								nameClass: 'w-max pb20'
							},
							{
								name: '发票照片',
								value: data.receive?.bill_pic || '',
								type: 'img',
								nameClass: 'w-max pb20'
							},
							{
								name: '快递单号照片',
								value: data.receive?.express_pic || '',
								type: 'img',
								nameClass: 'w-max pb20'
							},
						]
					},

				]
				return arr
			}
		},
	}
</script>

<style lang="scss">

</style>
